package com.elastic.demo;

import com.elastic.sort.BuilderType;
import com.elastic.sort.type.DefaultEnumType;
import com.elastic.sort.type.BaseEnumType;
import org.elasticsearch.search.sort.SortBuilder;
import org.elasticsearch.search.sort.SortBuilders;
import org.elasticsearch.search.sort.SortOrder;

/**
 * @ClassName InsignificanceBuilderType
 * @Author xiezhuocai
 * @Description TODO
 * @Date 2021/12/23 0:11
 */
public class InsignificanceBuilderType implements BuilderType {

    @Override
    public SortBuilder<?> setSort(BaseEnumType sortType) {
        SortBuilder<?> sortBuilder;
        DefaultEnumType defaultEnumType = (DefaultEnumType)sortType;
        switch (defaultEnumType) {
            case DEFAULT:
                sortBuilder = SortBuilders.scoreSort().order(SortOrder.DESC);
                break;
            //case NAME_DESC:
                //sortBuilder = SortBuilders.fieldSort("name").order(SortOrder.DESC);
                //break;
            default:
                throw new RuntimeException("排序类型错误");
        }
        return sortBuilder;
    }

}
